﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_QuanLy : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            OTOWeb.DataOut dto = new OTOWeb.DataOut();
            OTOWeb.HANGXE_ENTITY hangxe = new OTOWeb.HANGXE_ENTITY();
            DataSet ds = dto.DanhSachHangXe(hangxe);
            DropDownList1.DataSource = ds.Tables[0];
            DropDownList1.DataTextField = "TENHANG";
            DropDownList1.DataValueField = "MAHANG";
            DropDownList1.DataBind();
            ListLOAD();
        }
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListLOAD();
    }
    private void ListLOAD()
    {
        if (DropDownList1.SelectedItem.Value != "")
        {
            OTOWeb.DataOut dto = new OTOWeb.DataOut();
            OTOWeb.HANGXE_ENTITY hangxe = new OTOWeb.HANGXE_ENTITY();
            DataSet ds = dto.DanhSachXeTheoMaHang(DropDownList1.SelectedItem.Value);
            ListItem listitem;
            ListBox1.Items.Clear();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                listitem = new ListItem();
                listitem.Text = ds.Tables[0].Rows[i]["TENXE"].ToString();
                listitem.Value = ds.Tables[0].Rows[i]["MAXE"].ToString();
                ListBox1.Items.Add(listitem);
            }
        }
    }
    private void LoadGia()
    {
        if (ListBox1.Items.Count>0)
        {
            OTOWeb.DataOut dto = new OTOWeb.DataOut();
            DataSet ds = dto.Web_PhanTram(ListBox1.SelectedItem.Value);
            TextBox1.Text = ds.Tables[0].Rows[0]["PHANTRAM"].ToString();
        }
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        LoadGia();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        OTOWeb.DataOut dto = new OTOWeb.DataOut();
        if(ListBox1.SelectedItem.Value!=null && TextBox1.Text.Trim()!="")
        dto.Web_UPdatePhanTram(ListBox1.SelectedItem.Value,Convert.ToDecimal(TextBox1.Text));
    }
}